﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LongNet.Demo
{
    static class Population
    {
        public static void PrintPoputation()
        {
            int count60 = 0;
            int count40 = 1000000000;
            int count20 = 600000000;
            int count0 = 0;
            int years = 20; 
            int tempCount=0;
            int all = 0;
            int i = 0;
            System.Console.WriteLine(string.Format("这是一个抽象模拟人口变化,假如男女比例是1比1，1个男人都能娶到1个老婆。按任意键继续..."));
            System.Console.Read();    
            while (true)
            {
                i++;
                tempCount = count60;
                count0 = count20 / 2;
                count60 = count40;
                count40 = count20;
                count20 = count0;              
                System.Console.WriteLine(string.Format("{0}年之后，{1}年:", years * i, DateTime.Now.AddYears(years * i).ToString("yyyy-MM-dd")));             
                System.Console.WriteLine(string.Format("婴儿:{0}个，年轻人：{1}个，中年人：{2}个，老年人：{3}个,{4}个人老去死亡。\r\n", GetCount(count0), GetCount(count20), GetCount(count40), GetCount(count60), GetCount(tempCount)));
                all=count0 + count20 + count40 + count60;
                System.Console.WriteLine(string.Format("此时人口总数已剩:{0}个,其中人口分布比率为婴儿:{1}，年轻人：{2},中年人：{3}，老年人：{4}", GetCount(all), (float)count0 / (float)all, (float)count20 / (float)all, (float)count40 / (float)all, (float)count60 / (float)all));
                System.Threading.Thread.Sleep(3000);
                if (i > 9)
                    break;
            }                    
          
            System.Console.Read();
        }
        static string GetCount(int num)
        {
            string result = "";
            //60000 0000
            int hmillion = 0;
            int million = 0;
            //int thousand = 0;
            if (num > 100000000)
            {
                hmillion = num / 100000000;
                num = num % 100000000;
                result += string.Format("{0}亿",hmillion);
            }

            if (num > 10000)
            {
                million = num / 10000;
                num = num % 10000;
                result += string.Format("{0}万", million);
            }
            if (num > 1000)
            {
                million = num / 1000;
                num = num % 1000;
                result += string.Format("{0}千", million);
            }
            if (num > 100)
            {
                million = num / 100;
                num = num % 100;
                result += string.Format("{0}百", million);
            }
            if (num > 10)
            {
                million = num / 10;
                num = num % 10;
                result += string.Format("{0}十", million);
            }
            if (num > 0)
            {
                result += string.Format("{0}个", num);
            }           
            return result;
        }
    }
}
